<%@page import="com.gomore.wechat.mp.config.WxContext"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%
   String curActId = WxContext.getWxAccount() == null ? null: WxContext.getWxAccount().getId();
%>

<%@include file="/context/mytags.jsp"%>
<t:base type="jquery,easyui,tools,DatePicker"></t:base>
<div id="main_depart_list" class="easyui-layout" fit="true">
  <div region="center" style="padding:1px;">
  <t:datagrid name="weixinAccountList" checkbox="true" fitColumns="true" title="微信公众帐号信息" actionUrl="wxAccountController.do?datagrid" idField="id" fit="true" queryMode="group">
   <t:dgCol title="帐号名称"  field="name"  hidden="false" query="true" queryMode="single"  width="120"></t:dgCol>
   <%-- <t:dgCol title="公众帐号TOKEN"  field="token"  hidden="false"  queryMode="single"  width="120"></t:dgCol> --%>
   <t:dgCol title="微信号"  field="number"  hidden="false"  queryMode="single"  width="120"></t:dgCol>
   <t:dgCol title="原始ID"  field="originalId"  hidden="false" query="true"  queryMode="single"  width="120"></t:dgCol>
   <t:dgCol title="默认账号"  field="id"  hidden="false"  queryMode="single"  width="60" formatterjs="showActiveCol"></t:dgCol>
   <t:dgCol title="公众号类型"  dictionary="type" field="accounttype"  hidden="true"  queryMode="single"  width="120"></t:dgCol>
   <t:dgCol title="电子邮箱"  field="email"  hidden="true"  queryMode="single"  width="120"></t:dgCol>
   <t:dgCol title="公众帐号描述"  field="description"  hidden="true"  queryMode="single"  width="120"></t:dgCol>
   <t:dgCol title="APPID"  field="appid"  hidden="true"  query="true"  queryMode="single"  width="120"></t:dgCol>
   <t:dgCol title="公众帐号APPSECRET"  field="appsecret"  hidden="true"  queryMode="single"  width="120"></t:dgCol>
   <t:dgCol title="ACCESS_TOKEN"  field="accesstoken"  hidden="true"  queryMode="single"  width="120"></t:dgCol>
   <t:dgCol title="TOKEN到期时间"  field="expiresTime"  hidden="true"  queryMode="single"  width="120"></t:dgCol>
 
   <t:dgCol title="操作" field="opt" width="200"></t:dgCol>
   <t:dgDelOpt title="删除" url="wxAccountController.do?doDel&id={id}" />
   <t:dgFunOpt title="设置为默认账号"  funname="doActiveAccount(id)" />
   <t:dgFunOpt funname="queryMbrByAccountId(id)" title="查看管理员"></t:dgFunOpt>
   <t:dgToolBar title="创建公众账号" icon="icon-add" url="wxAccountController.do?goAdd" funname="myadd"></t:dgToolBar>
   <t:dgToolBar title="编辑" icon="icon-edit" url="wxAccountController.do?goUpdate" funname="update"></t:dgToolBar>
   
   <%--
   <t:dgToolBar title="批量删除"  icon="icon-remove" url="weixinAccountController.do?doBatchDel" funname="deleteALLSelect"></t:dgToolBar>
     --%>
   <t:dgToolBar title="查看" icon="icon-search" url="wxAccountController.do?goUpdate" funname="detail"></t:dgToolBar>
    <t:dgToolBar title="重置微信Token"  operationCode="doResetAccessToken" icon="icon-reload"  funname="doResetAccessToken"></t:dgToolBar>
  </t:datagrid>
  </div>
 </div>
 
 <div data-options="region:'east',
    title:'管理员列表',
    collapsed:true,
    split:true,
    border:false,
    onExpand : function(){
      li_east = 1;
    },
    onCollapse : function() {
        li_east = 0;
    }"
    style="width: 400px; overflow: hidden;" id="eastPanel">
      <div class="easyui-panel" style="padding:0px;border:0px" fit="true" border="false" id="userListpanel"></div>
  </div>
 
 <script src = "webpage/com/gomore/wechat/account/weixinAccountList.js"></script>		
 <script type="text/javascript">
 var li_east = 0;
 
 $(document).ready(function(){
 		//给时间控件加上样式
 });
 
 function showActiveCol(value,row,index){
     var curAccountId = "<%=curActId%>";
     if (value == curAccountId) {
         return "是";
     } else {
         return "否";
     }
 }
 
 function myadd(title,addurl,gname,width,height) {
		gridname=gname;
		var getData = $('#'+gridname).datagrid('getData');
		/* if(getData.total!=0){
			tip('一个用户只能创建一个公众账号');
			return;
		} */
		createwindow(title, addurl,width,height);
	}
 
 function doResetAccessToken(){
		var row = $('#weixinAccountList').datagrid('getSelected');
	    var url = "wxAccountController.do?doResetAccessToken";
		  if(row){
		   		url += "&accountid="+row.id;
		  }else{
			  tip("请选择微信公众号!");
			  return;
		  }
		  
		 $.ajax({
			url:url,
			type:"GET",
			dataType:"JSON",
			success:function(data){
				if(data.success){
					tip("微信公众号重置Token成功!");
				}else{
					tip(data.msg);
				}
			}
		});
	}
 
 function queryMbrByAccountId(accountId){
     var title = '管理员列表';
     if(li_east == 0 || $('#main_depart_list').layout('panel','east').panel('options').title != title){
         $('#main_depart_list').layout('expand','east');
     }
     $('#main_depart_list').layout('panel','east').panel('setTitle', title);
     $('#main_depart_list').layout('panel','east').panel('resize', {width: 300});
     $('#userListpanel').panel("refresh", "wxAccountController.do?mgrList&accountid=" + accountId);
 }
 
 function doActiveAccount(accountId){
		 var url = "wxAccountController.do?doActive&id=" + accountId;
		 $.ajax({
		  url:url,
		  type:"GET",
		  dataType:"JSON",
		  success:function(data){
		    if(data.success){
		      tip("操作成功!");
		      // reloadTable();
		      window.location.reload();
		    }else{
		      tip(data.msg);
		    }
		  }
		});
 }
 </script>